package org.adobe.utils {

	public class XMLUtil {
		public static const TEXT:String = "text";
		public static const COMMENT:String = "comment";
		public static const ATTRIBUTE:String = "attribute";
		public static const ELEMENT:String = "element";
		public static const PROCESSING_INSTRUCTION:String = "processing-instruction";

		public static function isValidXML(data:String):Boolean {
			var xml:XML;
			try {
				xml = new XML(data);
			} catch (e:Error){
				return false;
			}
			if (xml.nodeKind() != XMLUtil.ELEMENT){
				return false;
			}
			return true;
		}

		/**返回下一个节点*/
		public static function getNextSibling(x:XML):XML {
			return XMLUtil.getSiblingByIndex(x, 1);
		}
		
		/**返回上一个节点*/
		public static function getPreviousSibling(x:XML):XML {
			return XMLUtil.getSiblingByIndex(x, -1);
		}
		
		/**根据索引返回节点*/
		protected static function getSiblingByIndex(x:XML, count:int):XML {
			var out:XML;
			try {
				out = x.parent().children()[x.childIndex() + count];
			} catch (e:Error){
				return null;
			}
			return out;
		}
	}
}